import { SettingTypes } from "../type"
import { ISetting, IAction } from "./setting.type";

const initSetting: ISetting = {
    isOpen: true,//侧边栏是否展开
    tagShow: false,//标签页是否显示
    fixHeader: true,//顶部是否固定
    layout: 'vertical',//整体框架布局 vertical侧边栏 horizontal顶部+侧边栏 deployment 顶部+下拉页面
    logoPosition:'top',//logo所属组件位置 top side
    isAudio: false,//是否需要报警提示
    theme: 'default',//主题 default light
}

export const Setting = (state: ISetting = initSetting, action: IAction) => {
    let { type } = action;
    switch (type) {
        case SettingTypes.UPDATE_OPEN://更新侧边栏是否展开
            return {
                ...state,
                isOpen: !state.isOpen
            }
        case SettingTypes.UPDATE_TAG:
            return {
                ...state,
                tagShow: !state.tagShow
            }
        case SettingTypes.UPDATE_HEADER:
            return {
                ...state,
                fixHeader: !state.fixHeader
            }
        case SettingTypes.UPDATE_LAYOUT:
            return {
                ...state,
                layout: action.data
            }
        case SettingTypes.UPDATE_LOGO_POSITION:
            return {
                ...state,
                logoPosition: action.data
            }
        case SettingTypes.UPDATE_THEME:
            return {
                ...state,
                theme: action.data
            }
        case SettingTypes.UPDATE_AUDIO:
            return {
                ...state,
                isAudio: !state.isAudio
            }
        default:
            return state;
    }
}